{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1789667c-89b0-4d5c-993d-fab60e20fdbe",
   "metadata": {},
   "source": [
    "静电场，高斯定理，介质……\n",
    "\n",
    "至于不同形状，可能不太好办吧……"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "4a9b1d49-92bc-4da8-834c-bdb84651d37e",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "incompatible degrees in vector constructor",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[1], line 3\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[38;5;66;03m# 定义符号变量和向量\u001b[39;00m\n\u001b[1;32m      2\u001b[0m var(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mq ε μ\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 3\u001b[0m D \u001b[38;5;241m=\u001b[39m \u001b[43mvector\u001b[49m\u001b[43m(\u001b[49m\u001b[43mSR\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mInteger\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m3\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mD\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m  \u001b[38;5;66;03m# 电位移场\u001b[39;00m\n\u001b[1;32m      4\u001b[0m H \u001b[38;5;241m=\u001b[39m vector(SR, Integer(\u001b[38;5;241m3\u001b[39m), \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mH\u001b[39m\u001b[38;5;124m'\u001b[39m)  \u001b[38;5;66;03m# 磁场强度\u001b[39;00m\n\u001b[1;32m      5\u001b[0m v \u001b[38;5;241m=\u001b[39m vector(SR, Integer(\u001b[38;5;241m3\u001b[39m), \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mv\u001b[39m\u001b[38;5;124m'\u001b[39m)  \u001b[38;5;66;03m# 电荷速度\u001b[39;00m\n",
      "File \u001b[0;32m/usr/lib/python3.12/site-packages/sage/modules/free_module_element.pyx:553\u001b[0m, in \u001b[0;36msage.modules.free_module_element.vector (build/cythonized/sage/modules/free_module_element.c:10290)\u001b[0;34m()\u001b[0m\n\u001b[1;32m    551\u001b[0m else:\n\u001b[1;32m    552\u001b[0m     if not isinstance(arg2, dict) and len(arg2) != degree:\n\u001b[0;32m--> 553\u001b[0m         raise ValueError(\"incompatible degrees in vector constructor\")\n\u001b[1;32m    554\u001b[0m     arg1 = arg2\n\u001b[1;32m    555\u001b[0m \n",
      "\u001b[0;31mValueError\u001b[0m: incompatible degrees in vector constructor"
     ]
    }
   ],
   "source": [
    "# 定义符号变量和向量\n",
    "var('q ε μ')\n",
    "D = vector(SR, 3, 'D')  # 电位移场\n",
    "H = vector(SR, 3, 'H')  # 磁场强度\n",
    "v = vector(SR, 3, 'v')  # 电荷速度\n",
    "\n",
    "# 介质中的电场和磁感应强度\n",
    "E = D / ε               # 电场强度\n",
    "B = μ * H               # 磁感应强度\n",
    "\n",
    "# 计算洛伦兹力\n",
    "F = q * (E + v.cross_product(B))\n",
    "\n",
    "# 显示结果\n",
    "print(\"洛伦兹力公式（介质中）:\")\n",
    "show(F)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "SageMath 10.5",
   "language": "sage",
   "name": "sagemath"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
